﻿using AutoMapper;
using MediatR;
using Traceability.App.Api.Application.Command.Get;
using Traceability.App.Api.DTO;
using Traceability.App.Domain;
using Traceability.App.ErrorCode;
using Traceability.App.Instructure;

namespace Traceability.App.Api.Application.Handler.Get
{
    public class GetTuHandler : IRequestHandler<GetTuCommand, ApiResult<SlaughterModel>>
    {
        private readonly IBaseRepository<SlaughterModel> slaughterRepo;
        private readonly IMapper mapper;

        public GetTuHandler(IBaseRepository<SlaughterModel> slaughterRepo,IMapper mapper)
        {
            this.slaughterRepo = slaughterRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<SlaughterModel>> Handle(GetTuCommand request, CancellationToken cancellationToken)
        {
            ApiResult<SlaughterModel> res = new ApiResult<SlaughterModel>();
            var slaughter = slaughterRepo.GetAll().Where(x => x.Batch == request.Batch && x.IsDelete == false).FirstOrDefault();
            res.Data = slaughter;
            res.Code = ApiEnum.Success;
            res.Msg = "显示屠宰信息成功";
            return Task.FromResult(res);
        }
    }
}
